package com.shanzmoo.h5.domain.query;

import com.shanzmoo.db.product.entity.dto.ProductSpuQueryDto;
import com.shanzmoo.base.bean.PageReqBase;
import io.swagger.annotations.ApiModel;
import io.swagger.annotations.ApiModelProperty;
import lombok.*;

/**
 * 商品搜索参数
 *
 * @author： Gzhao 2020/12/27
 */
@Data
@Builder
@NoArgsConstructor
@AllArgsConstructor(access = AccessLevel.PRIVATE)
@ApiModel("商品分类搜索参数")
public class ProductSpuCategoryQuery extends PageReqBase {
    private static final long serialVersionUID = 1758L;

    @ApiModelProperty(value = "三级分类id")
    private Integer categoryId;

    @ApiModelProperty(value = "销量排序(无论，true/false 都是正序，null 不排序)")
    private Boolean saleSort;

    @ApiModelProperty(value = "价格排序：true-正序，false-倒序")
    private Boolean priceSort;

    public ProductSpuQueryDto convertToQuery() {
        ProductSpuQueryDto spuQueryDto = new ProductSpuQueryDto();
        spuQueryDto.setPageNum(this.getPageNum());
        spuQueryDto.setPageSize(this.getPageSize());
        spuQueryDto.setCategoryId(this.categoryId);

        if (this.saleSort == null && priceSort == null){
            spuQueryDto.setSaleSort(true);
        } else {
            spuQueryDto.setSaleSort(this.saleSort);
            spuQueryDto.setPriceSort(this.priceSort);
        }

        return spuQueryDto;
    }
}
